package DaiMa;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class Button {

    public static final int UP=1;
    public static final int DOWN=2;
    public static final int LEFT=3;
    public static final int RIGHT=4;

    public static void main(String[] args){
        JFrame win=new JFrame();

        JPanel panel =new JPanel();

        win.add(panel);

        JButton btn1=new JButton("上");
        JButton btn2=new JButton("下");
        JButton btn3=new JButton("左");
        JButton btn4=new JButton("右");

        panel.add(btn1);
        panel.add(btn2);
        panel.add(btn3);
        panel.add(btn4);

        win.setLocationRelativeTo(null);
        win.setSize(300,400);
        win.setVisible(true);

        btn1.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e){
                move(UP);
            }
        });

        btn2.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(DOWN);
            }
        });

        btn3.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(LEFT);
            }
        });

        btn4.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(RIGHT);
            }
        });

    }
    public static void move(int flag){
        switch(flag){
            case UP:
                System.out.println("玛丽向上飞了一下~");
                break;

            case DOWN:
                System.out.println("玛丽往下蹲了一下~");
                break;

            case LEFT:
                System.out.println("玛丽往左蹲了一下~");
                break;

            case RIGHT:
                System.out.println("玛丽往右跑了一下~");
                break;

        }
    }
}